package cn.bearspark.emoji.provider.rpc;

import cn.bearspark.emoji.dto.AddEmojisDTO;
import cn.bearspark.emoji.provider.service.EmojiService;
import cn.bearspark.emoji.provider.service.bo.EmojiUrlBO;
import cn.bearspark.emoji.rpc.EmojiRpc;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author f
 */
@Component
@DubboService
public class EmojiRpcImpl implements EmojiRpc {

    private final EmojiService emojiService;

    public EmojiRpcImpl(EmojiService emojiService) {
        this.emojiService = emojiService;
    }

    @Override
    public List<String> listAllEmojis() {
        return emojiService.listAllEmojis().stream().map(EmojiUrlBO::getEmojiUrl).toList();
    }

    @Override
    public void addEmojiList(AddEmojisDTO addEmojisDTO) {
        emojiService.addEmojiList(addEmojisDTO);
    }

    @Override
    public Map<Long, List<String>> mapEmojiSet(int moduleCode, Set<Long> moduleDataIdSet) {
        return emojiService.mapEmojiSet(moduleCode, moduleDataIdSet).entrySet().stream().collect(Collectors.toMap(
                Map.Entry::getKey,
                entry -> entry.getValue().stream().map(EmojiUrlBO::getEmojiUrl).toList()
        ));
    }

    @Override
    public void delete(int moduleCode, long moduleDataId) {
        emojiService.delete(moduleCode, moduleDataId);
    }
}
